package controller.KeyListeners;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.HashMap;

import javax.swing.KeyStroke;

public abstract class KeyboardListener extends KeyAdapter{
	protected boolean active = true;
	protected HashMap<KeyStroke,Action> keyBindings = new HashMap<KeyStroke,Action>();
	public void keyPressed(KeyEvent evt){
		if(active){
			Action toDo = keyBindings.get(KeyStroke.getKeyStroke(evt.getKeyCode(), evt.getModifiers()));
			if(toDo != null){
				toDo.perform();
			}
		}
	}
	public void activate(){
		active = true;
	}
	public void deactivate(){
		active = false;
	}
}
